javascript foreach key value

49

javascript foreach object key -

const obj = {
  name: 'Jean-Luc Picard',
  rank: 'Captain'
};

// Prints "name Jean-Luc Picard" followed by "rank Captain"
Object.keys(obj).forEach(key => {
  console.log(key, obj[key]);
});

js foreach key value -

Object.keys(obj).forEach(function (key) {
   // do something with obj[key]
});

Comments

Submit
0 Comments